package com.wandian.audio.mvvm.audiolibrary.audiolibrarypage;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mylib.libcore.mvvm.BaseMVVMFragment;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.audio.R;
import com.wandian.audio.adapter.AudioDJTopRecycleAdapter;
import com.wandian.audio.databinding.AudioFragmentLibiraryChildBinding;

/**
 * @author Administrator
 * @date 2019/12/16-13:30
 * @description DJ曲库-子页面
 **/
public class AudioLibraryChildFragment extends BaseMVVMFragment<AudioLibraryChildFragmentViewModel> implements BaseQuickAdapter.RequestLoadMoreListener{

    private AudioFragmentLibiraryChildBinding dataBinding;
    private AudioDJTopRecycleAdapter audioRankRecycleAdapter;
    private int page =1;

    private String title;
    private String value;
    public static AudioLibraryChildFragment newInstance(String title) {
        Bundle args = new Bundle();
        args.putString("title", title);
        AudioLibraryChildFragment fragment = new AudioLibraryChildFragment();
        fragment.setArguments(args);
        return fragment;

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        dataBinding = AudioFragmentLibiraryChildBinding.inflate(inflater);
        dataBinding.setLifecycleOwner(this);
        return dataBinding.getRoot();
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        dataBinding.setViewModel(mViewModel);

        title = getArguments().getString("title");
        if(!UIUtils.isEmpty(title)){
            switch (title){
                case "国内新闻":
                    value = "guonei";
                    break;
                case "国际新闻":
                    value = "world";
                    break;
                case "财经新闻":
                    value = "caijing";
                    break;
                case "军事新闻":
                    value = "military";
                    break;
          
            }
        }
        initRecycleView();
        initViewData();
         
    }

    private void initViewData(){
        
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {//视图变为可见
        }
    }

    private void initRecycleView(){

        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
        dataBinding.recyclerChild.setLayoutManager(layoutManager);
        audioRankRecycleAdapter  = new AudioDJTopRecycleAdapter(R.layout.audio_item_rank_style_one);
        dataBinding.recyclerChild.setAdapter(audioRankRecycleAdapter);

        dataBinding.srlRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

            }
        });

        audioRankRecycleAdapter.setOnLoadMoreListener(this, dataBinding.recyclerChild);
    }


    @Override
    public void onLoadMoreRequested() {

    }
}
